package com.qf.business.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.business.user.dao.TeacherDao;
import com.qf.business.user.service.TeacherService;
import com.qf.data.user.entity.Teacher;
import org.springframework.stereotype.Service;

/**
 * 教师表(Teacher)表服务实现类
 *
 * @author makejava
 * @since 2022-11-25 14:23:16
 */
@Service("teacherService")
public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> implements TeacherService {

    /**
     * 根据邮箱查询教师的信息
     * @param email
     * @return
     */
    @Override
    public Teacher queryByEmail(String email) {

        Teacher teacher = this.query()
                .eq("email", email)
                .one();

        if (teacher == null) {
            //首次自动注册
            teacher = new Teacher()
                    .setEmail(email)
                    .setName("游客" + (int)(Math.random() * 10000))
                    .setAge(0)
                    .setHeader(null)
                    .setInfo("这个人很懒，什么都没有留下");

            this.save(teacher);
        }

        return teacher;
    }
}

